package com.ibeeking.found.content.b.rest.controller.v1;

import com.ibeeking.found.content.b.rest.annotation.AccessLimit;
import com.ibeeking.found.content.b.rest.service.IBroadcastRoomService;
import com.ibeeking.found.content.service.common.param.BroadcastParam;
import com.ibeeking.found.content.service.common.query.BroadcastPageQuery;
import com.ibeeking.found.content.service.common.query.BroadcastQuery;
import com.ibeeking.found.content.service.common.query.BroadcastRoomIdPageQuery;
import com.ibeeking.found.content.service.common.vo.BroadcastCouponVO;
import com.ibeeking.found.content.service.common.vo.BroadcastGoodsVO;
import com.ibeeking.found.content.service.common.vo.BroadcastVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName BroadcastController控制器
 * @Description
 * @Author ibeeking
 * @Date 2022-02-18 14:11
 **/
@RestController
@RequestMapping("/b/broadcast/v1/room")
public class BroadcastRoomController {

    @Resource
    private IBroadcastRoomService broadcastRoomService;


    @Log(logType = OperateLogTypeEnum.QUERY, describe = "直播间列表")
    @PostMapping(value = "/list")
    public List<BroadcastVO> list(@RequestBody BroadcastQuery broadcastQuery) {
        return broadcastRoomService.list(broadcastQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "直播源查询")
    @PostMapping(value = "/source")
    public Map<String, List<BroadcastVO>> source(@RequestBody BroadcastQuery broadcastQuery) {
        return broadcastRoomService.source(broadcastQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "直播间分页列表")
    @PostMapping(value = "/pageList")
    public Page<BroadcastVO> pageList(@RequestBody BroadcastPageQuery broadcastPageQuery) {
        return broadcastRoomService.pageList(broadcastPageQuery);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "直播间添加")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) BroadcastParam broadcastParam) {
        return broadcastRoomService.add(broadcastParam);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "直播间修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) BroadcastParam broadcastParam) {
        return broadcastRoomService.modify(broadcastParam);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "直播间商品列表分页查询")
    @PostMapping(value = "/goods/page/list")
    public Page<BroadcastGoodsVO> goods(@RequestBody BroadcastRoomIdPageQuery pageQuery) {
        return broadcastRoomService.getGoodsPageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "直播间优惠券列表分页查询")
    @PostMapping(value = "/coupon/page/list")
    public Page<BroadcastCouponVO> getCouponPageList(@RequestBody BroadcastRoomIdPageQuery pageQuery) {
        return broadcastRoomService.getCouponPageList(pageQuery);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "直播间查看")
    @GetMapping(value = "/view/{id}")
    public BroadcastVO view(@PathVariable("id") Long id) {
        return broadcastRoomService.view(id);
    }

    @AccessLimit(seconds = 1, maxCount = 1)
    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "直播间公开状态修改")
    @PostMapping(value = "/changeStatus/{id}/{status}")
    public Integer changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return broadcastRoomService.changePublishStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "直播间删除")
    @PostMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return broadcastRoomService.del(id);
    }
}
